//
//  RightChatTableViewCell.m
//  HikingManager
//
//  Created by FENGYL on 2016/10/22.
//  Copyright © 2016年 FENGYL. All rights reserved.
//

#import "RightChatTableViewCell.h"

@interface RightChatTableViewCell()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttonWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttonHeight;


@end

@implementation RightChatTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setChatLogModel:(ChatLogModel *)chatLogModel{
    
    _chatLogModel = chatLogModel;
    
    CGSize maxSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - 60, MAXFLOAT);
    
    
    CGSize contentButtonSize = [chatLogModel.content boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0]} context:nil].size;
    
    _contentButton.titleLabel.numberOfLines = 0;
    
    _buttonWidth.constant = contentButtonSize.width + 25;
    _buttonHeight.constant = contentButtonSize.height + 20;
    
    [_contentButton setBackgroundImage:[self resizeImage:@"chatting_right_bg"] forState:UIControlStateNormal];
    [_chatTime setText:chatLogModel.time];
    
    [_contentButton setTitle:chatLogModel.content forState:UIControlStateNormal];
    
    _contentButton.userInteractionEnabled = NO;
    
    _cellHeight = contentButtonSize.height + 43;
}


-(UIImage * )resizeImage:(NSString *)imageName{
    UIImage * image = [UIImage imageNamed:imageName];
    CGFloat halfWidth = image.size.width/2;
    CGFloat halfHeight = image.size.height/2;
    UIEdgeInsets insets = UIEdgeInsetsMake(halfHeight, halfWidth, halfHeight, halfWidth);
    UIImage * newImage = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    return newImage;
}

@end
